﻿using System;

public partial class Services_RecuperarPassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void RecuperarPassword(object sender, EventArgs e)
    {
        DatabaseConnection dbCon = new DatabaseConnection();

        if (dbCon.UserExists(MatriculaTextBox.Text.ToUpper(), "Alumnos"))
        {
            if (dbCon.UserValidationCheck(MatriculaTextBox.Text.ToUpper()))
            {
                dbCon.CloseConnection();
                String alumnoMail = MatriculaTextBox.Text.ToUpper() + "@itesm.mx";
                MailService mc = new MailService();
                mc.PasswordRecoveryMail(alumnoMail);
                Session["UsuarioStatus"] = "<div class='alert alert-success' align='center'><strong>La nueva contrase&ntilde;a " +
                    "se ha enviado por correo a <span style='color: #3a87ad'> " + alumnoMail + "</span></strong></div>";
                Response.Redirect("~/Default.aspx");
            }
            else
            {
                dbCon.CloseConnection();
                Session["UsuarioStatus"] =
                    "<div class='alert alert-error' align='center'><strong>Tu cuenta a&uacute;n no est&aacute; activada.</span></strong></div>";
                Response.Redirect("~/Default.aspx");
            }

        }
        else
        {
            dbCon.CloseConnection();
            Session["UsuarioStatus"] =
                "<div class='alert alert-error' align='center'><strong>Usuario no registrado.</span></strong></div>";
            Response.Redirect("~/Default.aspx");
        }


    }
}